// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import { router } from './router'
import store from './store'
import { adapt } from '@/tool/initRem.js'
import { Swipe, SwipeItem } from 'c-swipe'
import axios from 'axios'
import VueCookie from 'vue-cookie'
import vScroll from 'vue-scroll'
import { InfiniteScroll } from 'mint-ui'
import setWechatTitle from '@/tool/setWechatTitle'
import config from './config'

Vue.use(VueCookie)
Vue.use(vScroll)
Vue.use(InfiniteScroll)

Vue.config.productionTip = false

// 公共组件的注册
Vue.component('swipe', Swipe)
Vue.component('swipe-item', SwipeItem)

// 设置设计稿的尺寸为750，1rem = 100px
const designWidth = 750
const rem2px = 100
adapt(designWidth, rem2px)

// icon scss
import './common/scss/icon.scss'

// reset css
import './common/scss/reset.scss'

// 配置Axios
let axiosBaseURL = ''

config.ISONLINESERVER ? axiosBaseURL = config.ONLINESERVER : axiosBaseURL = config.TESTSERVER

axios.defaults.baseURL = axiosBaseURL

Vue.prototype.$http = axios

// 配置vue-cookie
Vue.prototype.getUserCookie = function (key) {
  const value = this.$cookie.get(key)
  if (value != null) {
    this.$cookie.set(key, value, {
      expires: '7D'
    })
    return value
  } else {
    return null
  }
}

// 设置微信端上面的title
router.afterEach((route) => {
  setWechatTitle(route.meta.wechatTitle)
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})
